//
//  HNSH_IntegralBillHeader.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/1.
//

#import "HNSH_IntegralBillHeader.h"

@interface HNSH_IntegralBillHeader ()

/**  */
@property (nonatomic, strong)UIButton * timeBtn;

@end

@implementation HNSH_IntegralBillHeader

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}

//MARK: Myself Methods
- (void)addAllViews{
    [self addSubview:self.timeBtn];
    [self addSubview:self.typeBtn];
}

- (void)addAllLayout{
    [self.timeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(12);
        make.width.mas_equalTo(103);
        make.height.mas_equalTo(24);
    }];
    
    [self.typeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeBtn.mas_right).offset(16);
        make.top.mas_equalTo(12);
        make.width.mas_equalTo(103);
        make.height.mas_equalTo(24);
    }];
}

- (void)timeBtnAction{
    if (self.chooseTimeBlock) {
        self.chooseTimeBlock();
    }
}

//MARK: Setter Methods
- (void)setTime:(NSString *)time{
    _time = time;
    
    [self.timeBtn setTitle:[NSString stringWithFormat:@"%@ ", time] forState:UIControlStateNormal];
}

//MARK: Getter Methods
- (UIButton *)timeBtn{
    if (!_timeBtn) {
        _timeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_timeBtn setImage:[UIImage imageNamed:@"mine_bill_down_icon"] forState:UIControlStateNormal];
        [_timeBtn setTitle:[NSString stringWithFormat:@"%@ ", [NSString getToday]] forState:UIControlStateNormal];
        [_timeBtn setTitleColor:[UIColor appBlackLabelColor] forState:UIControlStateNormal];
        _timeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        _timeBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
        _timeBtn.layer.cornerRadius = 3;
        _timeBtn.layer.masksToBounds = YES;
        _timeBtn.backgroundColor = [UIColor appBGColor];
        [_timeBtn addTarget:self action:@selector(timeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _timeBtn;
}

- (UIButton *)typeBtn{
    if (!_typeBtn) {
        _typeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_typeBtn setImage:[UIImage imageNamed:@"mine_bill_down_icon"] forState:UIControlStateNormal];
        [_typeBtn setTitle:@" " forState:UIControlStateNormal];
        [_typeBtn setTitleColor:[UIColor appBlackLabelColor] forState:UIControlStateNormal];
        _typeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        _typeBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
        _typeBtn.layer.cornerRadius = 3;
        _typeBtn.layer.masksToBounds = YES;
        _typeBtn.backgroundColor = [UIColor appBGColor];
        _typeBtn.hidden = YES;
        WeakSelf(weakSelf);
        [[_typeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            UIButton *button = x;
            if (weakSelf.changeTypeBlock) {
                weakSelf.changeTypeBlock(button);
            }
        }];
    }
    return _typeBtn;
}

@end
